<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Publishres extends MY_Controller{
	function __construct(){
		parent::__construct();
	}

	public function index(){
		$this->load->view('publish/header');
		$this->load->view('publish/basic');
		$this->load->view('publish/footer');
	}

	public function main(){
		//发布资源页面
		$id = $this->input->get_post('id');
		$res = $this->ResourcesModel->get_res_by_id($id);
		$this->load->view('publish/header');
		$this->load->view('publish/main',array('res' => $res));
		$this->load->view('publish/footer');
	}

	public function detail(){
		//发布资源详细信息页面
		$res_id = $this->input->get_post('res_id');
		$res_name = $this->input->get_post('res_name');
		$res_type = $this->input->get_post('res_type');
		$res_desc = $this->input->get_post('res_desc');
		$subject = $this->input->get_post('subject');
		$size = $this->input->get_post('fileSize');
		$data = array(
			'resource_id' => $res_id,
			'resource_title' => $res_name,
			'resource_type' => $res_type,
			'resource_description' => $res_desc,
			'type' => 1,
			'share_time'=>date('Y-m-d H:i:s'),
			'subject' => $subject,
			'size' => $size
			);

		$id = $this->ResourceDescModel->add_rec_basic_desc($data);

		$this->load->view('publish/header');
		$this->load->view('publish/detail',array('res_name' => $res_name,'id' => $id));
		$this->load->view('publish/footer');
	}


	public function allres(){
		$userId = $this->get_user_id();
		$userName = $this->UsersModel->get_name_by_id($userId);
		$id = $this->input->get_post('res__desc_id');
		$res_suit = $this->input->get_post('res_suit');

		//Bug
		$result = $this->ResourceDescModel->add_res_detail_desc($id,$res_suit,$userId);


		$resourceNum = $this->ResourceDescModel->get_resource_num($userId);
		//我的提交资源信息
		$all_check_res = $this->ResourceDescModel->get_all_check_res($userId);//echo(json_encode($all_check_res));
		// $this->load->view('publish/header');
		// $this->load->view('ring/allres',array('all_check_res' => $all_check_res));
		// $this->load->view('publish/footer');
		
		$data = array(
			'userName' => $userName,
			'menuTitle' => 'sharesMenu',
			'all_check_res' => $all_check_res,
			'menuTitle' => 'checkShares',
			'resourceNum' => $resourceNum,
			// 'userId' => $userId
		);

		$this->load->view('ringCloud/checkShares',$data);
	}

	public function checkres(){

		$checkres = $this->ResourceDescModel->get_admin_check_res();
		
			//管理员审核信息页面（需要审核的所有资源）
			$this->load->view('publish/header');
			$this->load->view('publish/checkres',array('checkres' => $checkres));
			$this->load->view('publish/footer');
				
	}

	public function resInfo(){

		$id = $this->input->get_post('id');
		$detail = $this->ResourceDescModel->get_check_res_by_id($id);
		
		$user_name = $this->ResourcesModel->get_username_by_resid($detail['resource_id']);

		//管理审核资源详细页面
		$this->load->view('publish/header');
		$this->load->view('publish/resInfo',array('detail' => $detail,'user_name' => $user_name));
		$this->load->view('publish/footer');
	}



	

	public function ajax_admin_pass_check(){
		$id = $this->input->get_post('id');
		$new_res_desc = $this->input->get_post('new_res_desc');
		$admin_advice = $this->input->get_post('admin_advice');
		$result = $this->ResourceDescModel->add_admin_pass_advice($id,$new_res_desc,$admin_advice);
		// $query = $this->db->where('id',$id)->get('resource_desc')->result();
		$query = $this->db->get_where('resource_desc',array('id' => $id))->result();
		$userId = $query[0]->userId;
		$userName = $this->db->where('id',$userId)->get('users')->result()[0]->userName;
		$data = array(
			'upload_user_name' => $userName,
			'resource_id' => $query[0]->resource_id,
			'resource_name' => $query[0]->resource_title,
			'subject' => $query[0]->subject,
			'update_time' => $query[0]->share_time,
			'size' => $query[0]->size
		);
		$this->db->insert('public_resource',$data);
	}

	public function ajax_admin_deny_check(){

		$id = $this->input->get_post('id');
		$new_res_desc = $this->input->get_post('new_res_desc');
		$admin_advice = $this->input->get_post('admin_advice');
		$deny_reason = $this->input->get_post('deny_reason');

		$result = $this->ResourceDescModel->add_admin_deny_advice($id,$new_res_desc,$admin_advice,$deny_reason);

	}
	
	public function publicresInfo(){

		$id = $this->input->get_post('id');
		// $id = 4;
		$res_info = $this->ResourceDescModel->get_res_info_by_id($id);
		//公共云平台资源展示页面
		$this->load->view('publish/header');
		$this->load->view('publish/publicResInfo',array('res_info' => $res_info));
		$this->load->view('publish/footer');
	}

	public function ajax_check_share(){
		$id = $this->input->get_post('id');
		$result = $this->ResourceDescModel->check_share($id);
		// var_dump($result);exit();
		$json = array('success' => $result);
		echo json_encode($json);
		exit(0);
	}
}